package example.simpleservice1;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;

public class SimpleService1Activity extends Activity {
    private static final String TAG = "SimpleService1Activity";

    Context context;
    
    Intent myServiceIntent;
    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        context = this;
        myServiceIntent = new Intent(context, MyService.class);
        
        
        ToggleButton serviceToggleButton = (ToggleButton) findViewById(R.id.serviceToggleButton);
        
        serviceToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
			
			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
				if(isChecked){
					
					startService(myServiceIntent);
				}else{
					stopService(myServiceIntent);
				}
			}
		});
        
        Log.i(TAG, "i am started!");
        
    }
    
    @Override
    protected void onDestroy() {
    	super.onDestroy();
    }
    
}